package com.bjc2;

/**
 * @program: jvm_demo
 * @description:
 * @author: bjc
 * @create: 2022-03-01 21:58
 */
public class SonTest {

    public static void main(String[] args) {
        Father f = new Son();
        System.out.println(f.x);
    }
}

/**
 * 成员变量（非静态）赋值过程：1.默认初始化-2。显式初始化/代码块中初始化-3.构造器中初始化-4.有了对象之后，可以“对象.属性”或“对象.方法”
 * 的方式对成员变量进行赋值
 */
class Father{
    int x = 10;

    public Father() {
        this.print();
        this.x = 20;
    }

    public void print(){
        System.out.println("Father.x="+x);
    }
}

class Son extends Father{
    int x = 30;

    public Son() {
        this.print();
        x=40;
    }

    @Override
    public void print(){
        System.out.println("Son.x="+x);
    }
}
